const fs = require('fs');
const path = require('path');
const process = require('node:process')
const { spawn } = require('child_process');
const { oxlintPlugin } = require('./vite-plugin-oxlint/index.js')
const oxlintPluginConfig = {
  path: 'src',
  params: [
    '-c',
    `${path.join(process.cwd(), 'oxlintrc.json')}`,
    '--ignore-path',
    `${path.join(process.cwd(), '.eslintignore')}`,
    '--disable-react-plugin',
    '--disable-unicorn-plugin',
    '--disable-typescript-plugin',
    '--promise-plugin',
    '--jsx-a11y-plugin',
    // '--fix', 更多提示输出对电脑性能开销太大。建议关闭
    '--deny-warnings',
    `${path.join(process.cwd(), 'src')}`
  ],
}
module.exports = {
  configureWebpack: {
    plugins: [
      {
        apply: (compiler) => {
          compiler.hooks.invalid.tap('InvalidPlugin', (filePath) => {
            console.log(`File changed:==========>>>>>>> ${filePath}`);
          });
          compiler.hooks.run.tap('RunPlugin', (compiler) => {
            console.log('Webpack build process started');
          });
          compiler.hooks.done.tap('DonePlugin', async (stats) => {
           await oxlintPlugin(oxlintPluginConfig).handleHotUpdate()
          });
        }
      }
    ]
  }
};
